package lc_剑指_Offer_II_090_环形房屋偷盗;

public class Solution {

    int[] nums;

    public int rob(int[] nums) {
        this.nums = nums;
        int n = nums.length;
        return Math.max(f(0, n - 1), f(1, n));
    }

    private int f(int l, int r) {
        if (l == nums.length) {
            return -1;
        }
        int s = nums[l], p = 0;
        int cs = 0, cp = 0;
        for (int i = l + 1; i < r; i++, s = cs, p = cp) {
            cs = p + nums[i];
            cp = Math.max(s, p);
        }
        return Math.max(s, p);
    }

}